using System.Collections;
using BCW;
using Holoville.HOTween;
using I2.Loc;
using UnityEngine;

public class SkinForExportButton : MonoBehaviour
{
	public UIWidget widget;

	public UISprite background;

	public UILabel title;

	public UISprite icon;

	public UIBasicSprite texture;

	public UISprite selectedBG;

	[HideInInspector]
	public SkinsExporterPanel parentPanel;

	public string id;

	private ResourceRequest resourceRequest;

	public virtual void Awake()
	{
		HOTween.Init();
	}

	public virtual void Init(string id, SkinsExporterPanel parentPanel)
	{
		this.parentPanel = parentPanel;
		this.id = id;
		if ((bool)title)
		{
			title.text = ((!string.IsNullOrEmpty(ScriptLocalization.Get("Market/" + id + "_title"))) ? ScriptLocalization.Get("Market/" + id + "_title") : "Нет локализации");
		}
		Select(parentPanel.selected.Equals(id));
	}

	public virtual void OnClick()
	{
		Select(true);
	}

	public virtual void Select(bool selected)
	{
		if (selected)
		{
			if (parentPanel.selectedButton != this)
			{
				if ((bool)parentPanel.selectedButton)
				{
					parentPanel.selectedButton.Select(false);
				}
				parentPanel.selectedButton = this;
				selectedBG.alpha = 1f;
			}
		}
		else
		{
			selectedBG.alpha = 0f;
		}
	}

	public virtual void SetIcon()
	{
		icon.spriteName = id;
	}

	public IEnumerator LoadProductTextureCoroutine(Product product)
	{
		texture = texture.ReplaceForCurrentPlatform();
		yield return StartCoroutine(texture.LoadTextureAndAlphaMaskAsync(settings.shopTextureFolderPath, product.texture));
		texture.gameObject.SetActive(true);
		if ((bool)icon)
		{
			icon.gameObject.SetActive(false);
		}
	}

	public virtual void LoadProductTexture(Product product)
	{
		if (product != null)
		{
			CoroutineRunner.Instance.StartCoroutine(LoadProductTextureCoroutine(product));
		}
	}

	public void UnloadProductTexture()
	{
		if (resourceRequest != null && resourceRequest.asset != null)
		{
			Resources.UnloadAsset(resourceRequest.asset);
			texture.mainTexture = null;
		}
	}
}
